package name.williamwall.buxoid;

import android.app.ListActivity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class HelpVideos extends ListActivity {
    private static final String [] titles = {
       "Overview",
       "Settings and Update",
       "Accounts",
       "Transactions",
       "Budgets",
       "Expenses",
       "Impacts"
    };
    
    private static final String [] uris = {
        "http://www.youtube.com/watch?v=aEP7zkoAf1g", // overview
        "http://www.youtube.com/watch?v=gizqIRMuK2I", // settings and update
        "http://www.youtube.com/watch?v=fGdo6Q2ExCk", // acounts
        "http://www.youtube.com/watch?v=a4NIMalU8UA", // transactions
        "http://www.youtube.com/watch?v=2EWR4_SnATw", // budgets
        "http://www.youtube.com/watch?v=IUiTvAv1dQ8", // expenses
        "http://www.youtube.com/watch?v=ioC2rA5-1z8" // impacts
    };
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setTitle("Buxoid: Help Videos");
        setContentView(R.layout.videos);
    }
    
    @Override
    protected void onResume() {
        super.onResume();
        fillData();
    }
    
    private void fillData() {
        setListAdapter(new ArrayAdapter<String>(
                this, android.R.layout.simple_list_item_1, titles));
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        launchYouTube(uris[position]);
    }
    
    private void launchYouTube(String uriStr) {
        Uri uri = Uri.parse(uriStr);
        // check if others handle this url
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        intent.addCategory(Intent.CATEGORY_BROWSABLE);
        try {
            startActivity(intent);
        } catch (ActivityNotFoundException ex) {
          // fail
        }
    }
}
